<template>
    <BasicModal v-bind="$attrs" @register="registerModal" :title="modalTitle" @ok="onButtonOkClick">
        <BasicTable @register="registerForm" />
    </BasicModal>
</template>
<script lang="ts">
import { defineComponent, ref, unref, inject } from 'vue';
import { BasicModal, useModalInner } from '/@/components/Modal';
import { BasicTable, useTable } from '/@/components/Table/index';
import { StudentScoreColumns } from './student.data';
import { getScore } from '/@/api/demo/student';
import { useMessage } from '/@/hooks/web/useMessage';
// const { createMessage, createErrorModal } = useMessage();
const { createMessage } = useMessage();

export default defineComponent({
    name: 'AddStudent',
    components: { BasicModal, BasicTable },
    emits: ['success', 'register'],
    setup(_, { emit }) {
        //调用后台接口获取部门信息进行部门列表赋值
        //获取定义的表单，设置其中需要动态加载的部门数据列表
        const StudenScoretFormSchema = StudentScoreColumns;

        const dataId = ref('');
        const moduleName = inject<string>('moduleName');
        //标题--根据传入的模块名称+操作类型组合得到
        const modalTitle = ref('标题');
        const [registerForm, { reload, setTableData }] = useTable({
            columns: StudenScoretFormSchema,
        });
        const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
            //根据传递过来的参数获取对应的操作，操作不同所对应的界面不同
            //接收父组件传递的数据
            if (data?.dataId) {
                dataId.value = data.dataId;
            }

            if (moduleName) {
                modalTitle.value = unref(moduleName) + '--查看成绩';
            }

            setModalProps({ confirmLoading: false });
            getScore({ no: dataId.value })
                .then((res) => {
                    console.log('res', res);
                    setTableData(res);
                })
                .catch((ex) => {
                    console.log('catch ', ex);
                    createMessage.error(ex.msg);
                });

        });
        function onButtonOkClick() {
            closeModal();
        }
        // function getAllValid(id) {
        //     getScore({ no: id })
        //         .then((res) => {
        //             console.log('res', res);
        //             return res;
        //         })
        //         .catch((ex) => {
        //             console.log('catch ', ex);
        //             createMessage.error(ex.msg);
        //         });
        // }


        return {
            dataId,
            moduleName,
            modalTitle,
            registerForm,
            registerModal,
            onButtonOkClick
        };
    },
});
</script>
